//
//  MKTChatMsgTextTVCellOther.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2021/7/9.
//  Copyright © 2021 moon. All rights reserved.
//

#import "MKTChatMsgTextTVCellOther.h"

@implementation MKTChatMsgTextTVCellOther
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    }
    return self;
}
- (void)customLayoutSubviews{
    [super customLayoutSubviews];
    CGRect bounds = self.contentView.bounds;
    self.msgTextBubbleLayout.bounds = bounds;
    [self.msgTextBubbleLayout layoutItemsWithResizeItems:YES];
}
- (void)customReloadCellModel{
    [super customReloadCellModel];
    MKTChatMsgText *msg = self.chatMsg;
    self.msgTextBubbleView.textLabel.text = msg.text;
    [self.mk_tableViewOfFirst mk_dismissSubViewPopoverAnimated:NO completion:nil];
}
- (CGSize)customSizeThatFits:(CGSize)size{
    return [self.msgTextBubbleLayout sizeThatFits:size resizeItems:YES];
}
- (BOOL)enableLongPress{
    return YES;
}
- (void)didLongPress:(CGPoint)point{
    UITableView *tableView = self.mk_tableViewOfFirst;
    if(!tableView)return;
    UIView *contentView = self.msgTextBubbleView;
    CGPoint p2 = [self convertPoint:point toView:contentView];
    if(![contentView pointInside:p2 withEvent:nil]) return;
    
    MKUIPopoverMenuListView *popView = [[MKUIPopoverMenuListView alloc] init];
    [popView addMenu:[MKUIPopoverMenu menuWithTitle:@"复制" whenClick:^(MKUIPopoverMenu * _Nonnull menu) {
        UIPasteboard.generalPasteboard.string = self.msgTextBubbleView.textLabel.text;
    }]];
    [popView presentPopoverPointToView:contentView inContainerView:tableView animated:YES completion:nil];
}
@end
